package com.cheng.chengrobot.service.gpt;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cheng.chengrobot.mappers.GptChatHistoryMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GptChatHistoryService
{
    @Autowired
    private GptChatHistoryMapper gptChatHistoryMapper;

    public GptChatHistoryMapper gptMemoryMapper()
    {
        return this.gptChatHistoryMapper;
    }

    public boolean insert(com.cheng.chengrobot.domain.GptChatHistory gptChatHistory)
    {
        return gptChatHistoryMapper.insert(gptChatHistory) == 1;
    }

    public List<com.cheng.chengrobot.domain.GptChatHistory> selectRecentTen(Long robotQQ, Long groupQQ, Long qq)
    {
        QueryWrapper<com.cheng.chengrobot.domain.GptChatHistory> gptMemoryQueryWrapper = new QueryWrapper<>();
        gptMemoryQueryWrapper.eq("robot_qq", robotQQ);
        gptMemoryQueryWrapper.eq("qq", qq);
        gptMemoryQueryWrapper.orderByDesc("time").last("limit 11");
        if (groupQQ == null) {gptMemoryQueryWrapper.isNull("group_qq");}
        else {gptMemoryQueryWrapper.eq("group_qq", groupQQ);}
        return gptChatHistoryMapper.selectList(gptMemoryQueryWrapper);
    }
}
